import unittest
import utils
import requests

from api.login import LoginApi
from parameterized import parameterized


class TestSmsCode(unittest.TestCase):

    @classmethod
    def setUpClass(cls) -> None:
        cls.login_api = LoginApi()

    def setUp(self) -> None:
        self.session = requests.Session()

    def tearDown(self) -> None:
        self.session.close()

    # 获取短信验证码成功(正确的手机号,验证码,类型)
    @parameterized.expand(utils.build_data("sms_code.json"))
    def test01_get_sms_code(self, desc, phone, imgVerifyCode, status_code, status, description):
        print(f"desc={desc} phone={phone} imgVerifyCode={imgVerifyCode} "
              f"status_code={status_code} status={status} description={description}")
        # 测试数据
        # phone = "18800011121"
        # imgVerifyCode = "8888"

        # 调用接口
        # 获取图片验证码
        r = self.login_api.get_img_verify_code(self.session, 0.111111)
        self.assertEqual(200, r.status_code)

        # 获取短信验证码
        r = self.login_api.get_sms_code(self.session, phone, imgVerifyCode)
        print("get_sms_code data=", r.json())

        # 断言
        # self.assertEqual(200, r.status_code)
        # self.assertEqual(200, r.json().get("status"))
        # self.assertIn("短信发送成功", r.json().get("description"))
        utils.common_assert(self, r, status_code, status, description)

    # # 获取短信验证码成功(正确的手机号,验证码,类型)
    # def test01_get_sms_code_success(self):
    #     # 测试数据
    #     phone = "18800011121"
    #     imgVerifyCode = "8888"
    #
    #     # 调用接口
    #     # 获取图片验证码
    #     r = self.login_api.get_img_verify_code(self.session, 0.111111)
    #     self.assertEqual(200, r.status_code)
    #
    #     # 获取短信验证码
    #     r = self.login_api.get_sms_code(self.session, phone, imgVerifyCode)
    #     print("get_sms_code data=", r.json())
    #
    #     # 断言
    #     # self.assertEqual(200, r.status_code)
    #     # self.assertEqual(200, r.json().get("status"))
    #     # self.assertIn("短信发送成功", r.json().get("description"))
    #     utils.common_assert(self, r, 200, 200, "短信发送成功")
    #
    #
    # # 获取短信验证码失败(图片验证码错误)
    # def test02_get_sms_code_for_img_code_error(self):
    #     # 测试数据
    #     phone = "18800011121"
    #     imgVerifyCode = "1111"
    #
    #     # 调用接口
    #     # 获取图片验证码
    #     r = self.login_api.get_img_verify_code(self.session, 0.111111)
    #     self.assertEqual(200, r.status_code)
    #
    #     # 获取短信验证码
    #     r = self.login_api.get_sms_code(self.session, phone, imgVerifyCode)
    #     print("get_sms_code data=", r.json())
    #
    #     # 断言
    #     # self.assertEqual(200, r.status_code)
    #     # self.assertEqual(100, r.json().get("status"))
    #     # self.assertIn("图片验证码错误", r.json().get("description"))
    #     utils.common_assert(self, r, 200, 100, "图片验证码错误")
